'use strict';

/**
 * @ngdoc function
 * @name jgappApp.controller:ManageTbapplyCtrl
 * @description
 * # ManageTbapplyCtrl
 * Controller of the jgappApp
 */
angular.module('jgappApp')
    .controller('ManageTbapplyCtrl', function ($scope, openApi, $http, Util, $location, $rootScope, $routeParams, FormSubmit) {
        $scope.sheetObj = {};
        $scope.param = {};
        // 底部款项类型选框添加
        var tbway = {};
        tbway.sheettitle = "投标方式"
        tbway.callback = function (item) {
            $scope.param.bidTypeStr = item.selectTab
            $scope.param.bidTypeStrContent = item.selectTabContent
        }
        $scope.getTbType = function () {
            var param = {};
            param.type = "投标方式";
            Util.getKeyValue(param, function (data) {
                tbway.tabList = data.data
                $scope.showSheet("tbway")
            })
        };
        $scope.sheetObj.tbway = tbway;
        // 工程类型
        var projectTypeObj = {};
        projectTypeObj.sheettitle = "工程类型";
        projectTypeObj.callback = function (item) {
            $scope.param.projectType = item.selectTab
            $scope.param.projectTypeContent = item.selectTabContent
        }
        $scope.showprojectTypeObj = function () {
            var param = {};
            param.type = "工程类型";
            Util.getKeyValue(param, function (data) {
                projectTypeObj.tabList = data.data
                $scope.showSheet("projectTypeObj")
            })

        };
        $scope.sheetObj.projectTypeObj = projectTypeObj;

        $scope.showSheet = function (type) {
            var sheetObj = $scope.sheetObj[type]
            $scope.sheetObj.type = type
            $scope.sheetObj.tabList = sheetObj.tabList
            $scope.sheetObj.sheettitle = sheetObj.sheettitle
            $scope.sheetObj.ifshowSheet = true
            $rootScope.showMasker = true
        };

        $scope.choosePeople = function () {
           var relModuleObj = {
                name: "ManageTbapplyCtrl",
                selectTab: "select_customer",
                selectTabContent: "客户"
            };
            // 清掉关联的编号
            Util.savaParamForReview($scope.param, $routeParams.id);
            Util.savaDataforsearch(relModuleObj);
            $location.path("finance/choosepeople")
        }
        $scope.submit = function () {
            // 底部类型end
            if (!$scope.param.qualityReq) {
                Util.Toast("请填写资质要求");
                return;
            }
            if (!$scope.param.performanceReq) {
                Util.Toast("请填写业绩要求");
                return;
            }
            if (!$scope.param.otherReq) {
                Util.Toast("请填写其他要求");
                return;
            }
            if (!$scope.param.bidTypeStr) {
                Util.Toast("请填写投标方式");
                return;
            }
            if (!$scope.param.developers) {
                Util.Toast("请填写建设单位");
                return;
            }
            if (!$scope.param.projectName) {
                Util.Toast("请填写工程名称");
                return;
            }
            if (!$scope.param.projectType) {
                Util.Toast("请填写工程类型");
                return;
            }
            // 提交
            var urlParam = "?operationId=-2" + "&&processId=" + $routeParams.id + "&&url=" + openApi.bidApply
            var options = {};
            options.urlParam = urlParam;
            options.param = $scope.param
            var TVtype;
            TVtype = Util.getTVType(); //根据页面的来源来判断是发起的流程还是修改的流程，如果是发起的则不管，如果是修改的则获取数据用来回显
            // 如果是修改页面的话则提交的地址不一样，参数一样
            if (TVtype == Util.UPDATE) {
                options.url = openApi.ip + openApi.bidApply
            }
            new FormSubmit(options);
        };
        var init = function () {
            // 获取回显的详细信息
            Util.getDetailData($routeParams.id, function (data) {
                $scope.param = data;
            });
            // 显示审批记录判断
            Util.showloglist($routeParams.id, function (data) {
                $scope.logData = data;
            });

        };
        // 初始化
        init();
    });
